package com.hornsun.repository;

import com.hornsun.domain.dbo.OrderForm;
import com.hornsun.domain.dbo.OrderFormDetail;
import com.hornsun.domain.dbo.OrderFormDetailExample;
import com.hornsun.repository.mapper.OrderFormDetailMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by 编译中... on 2018/4/25.
 */
@Repository
public class OrderFormDetailRepository {

    @Resource
    private OrderFormDetailMapper orderFormDetailMapper;

    public List<OrderFormDetail> selectOrderDetail(String orderGuid){
        OrderFormDetailExample orderFormDetailExample = new OrderFormDetailExample();
        OrderFormDetailExample.Criteria criteria = orderFormDetailExample.createCriteria();
        criteria.andOrderGuidEqualTo(orderGuid);
        return orderFormDetailMapper.selectByExample(orderFormDetailExample);
    }

    public void insertOrderDetail(OrderFormDetail orderFormDetail){
        int count = orderFormDetailMapper.insertSelective(orderFormDetail);
        if (count!=1){
            throw new IllegalArgumentException("insert orderDetail failed by orderDetail:"+orderFormDetail);
        }
    }

    public void deleteOrderDetail(String orderGuid){
        OrderFormDetailExample orderFormDetailExample = new OrderFormDetailExample();
        OrderFormDetailExample.Criteria criteria = orderFormDetailExample.createCriteria();
        criteria.andOrderGuidEqualTo(orderGuid);
        int count = orderFormDetailMapper.deleteByExample(orderFormDetailExample);
        if (count!=1){
            throw new IllegalArgumentException("delete orderDetail failed by orderGuid:"+orderGuid);
        }
    }


}
